package com.example.androidtraining_ahut2020;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.Toast;

public class MainActivityDay09Login extends AppCompatActivity {
    ListView list;
    Button btnSignIn, btnRegister;
    EditText editTextUserName, editTextPassword;//PassWord //bad

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main_day09_login);
        btnSignIn = findViewById(R.id.signin_button);
        btnRegister = findViewById(R.id.bt_enroll);
        editTextUserName = findViewById(R.id.username_edit);
        editTextPassword = findViewById(R.id.password_edit);
        btnSignIn.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                String userName = editTextUserName.getText().toString().trim();
                String password = editTextPassword.getText().toString();
                //if(userName.equals("admin")&& password.equals("admin")){////userName=null  ==>NPE 闪退
                if ("admin".equals(userName) && "admin".equals(password)) {//userName=null  ==>false;
                    Intent intent = new Intent(MainActivityDay09Login.this, MainActivityDay09LoginSuccess.class);
                    Bundle bundle = new Bundle();
                    bundle.putString("user", userName);
                    intent.putExtras(bundle);
                    startActivity(intent);
                } else {
                    Toast.makeText(MainActivityDay09Login.this, "登录失败", Toast.LENGTH_SHORT).show();
                }
            }
        });


    }
}